package org.fxd;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.Tables;
import com.deepoove.poi.data.style.BorderStyle;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import org.fxd.dto.StudentDto;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TableDemo {

    public static void main(String[] args) throws Exception {

        Map<String, Object> map = new HashMap<>();
        map.put("table0", Tables.of(new String[][]{
                new String[]{"00", "01"},
                new String[]{"10", "11"}
        }).border(BorderStyle.DEFAULT).create());


        List<StudentDto> list = new ArrayList<>();
        list.add(new StudentDto("张三", "1班", 19, "山西"));
        list.add(new StudentDto("李四", "2班", 18, "河北"));
        list.add(new StudentDto("王五", "3班", 17, "山西"));
        list.add(new StudentDto("赵六", "1班", 16, "山西"));
        map.put("list", list);


        // 绑定表格循环插件
        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
        Configure config = Configure.builder()
                .bind("list", policy).build();
        XWPFTemplate template = XWPFTemplate.compile("E:\\log\\template.docx", config);
        template.render(map);
        template.writeAndClose(new FileOutputStream("E:\\log\\output.docx"));
        System.out.println("更新完成");
    }

}
